//
//  LTOauthViewController.swift
//  LTWeibo
//
//  Created by mac on 16/6/25.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

class LTOauthViewController: UIViewController {
    
    private lazy var webView: UIWebView = {
    
        let view = UIWebView()
        view.delegate = self
        let url = NSURL(string: "https://api.weibo.com/oauth2/authorize?client_id=\(APPKEY)&redirect_uri=\(REDIRECT_URI)")!
        let request = NSURLRequest(URL: url)
        view.loadRequest(request)
        return view
    
    }()
    
    
    
    
    override func loadView() {
        view = webView
    }

    
    
    override func viewDidLoad() {

        setColor()
        
        settingNav()
        
        
        
    }
    
    //设置导航条的按钮
    func settingNav() {
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "取消", style: UIBarButtonItemStyle.Plain, target: self, action: "cancelBtnClick")
    
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "自动填充", style: UIBarButtonItemStyle.Plain, target: self, action: "autoFillBtnClick")
    
    }
    
    
    //设置背景颜色
    func setColor() {
        
     view.backgroundColor = UIColor.whiteColor()
    
    }
    
    
    
    //取消实现
    func cancelBtnClick() {
  
        dismissViewControllerAnimated(true, completion: nil)
    }
    
    
    //自动填充功能的实现
    func autoFillBtnClick() {
    
    
    }
    
    

}



extension LTOauthViewController: UIWebViewDelegate {
    func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
        
        return true
    }
}
